import store from '@/store';
import  localCache  from '@/utils/cache';

import { createRouter, createWebHistory } from 'vue-router'
import { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue'),
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/main/main.vue'),
  },

  {
    path: '/:pathMatch(.*)',
    name: 'not-found',
    component: () => import('@/views/not-found/not-found.vue'),
  },

]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
})

router.beforeEach((to)=>{
  if(to.path !== '/login'){
    const token = localCache.getCache('token')
    if(!token){
      return '/login'
    }
    
  }
})



export default router
